import i18n from '@/i18n'
import { DomainModel } from '@apps/meta/domain/model'
import { Injectable } from '@nestjs/common'
import { MetaPlatformAuthDto } from '../system/meta-platform/dto/meta-platform-auth.dto'
import { MetaPlatformGetBindDataSourceTypeDto } from '../system/meta-platform/dto/meta-platform-get-bind-data-source-type.dto'
import { MetaPlatformGetBindDataSourceDto } from '../system/meta-platform/dto/meta-platform-get-bind-data-source.dto'
import { MetaPlatformGetChartDataDto } from '../system/meta-platform/dto/meta-platform-get-chart-data.dto'
import { MetaPlatformGetRealtimeDataDto } from '../system/meta-platform/dto/meta-platform-get-realtime-data.dto'
import { MetaPlatformRequestResourceModuleActionDto } from '../system/meta-platform/dto/meta-platform-request-resource-module-action.dto'
import { MetaPlatformWsAuthDto } from '../system/meta-platform/dto/meta-platform-ws-auth.dto'
import { MetaPlatformGetBindDataSourceTypeVo } from '../system/meta-platform/vo/meta-platform-get-bind-data-source-type.vo'
import { MetaPlatformGetBindDataSourceVo } from '../system/meta-platform/vo/meta-platform-get-bind-data-source.vo'
import { MetaPlatformGetChartDataVo } from '../system/meta-platform/vo/meta-platform-get-chart-data.vo'
import { MetaPlatformGetRealtimeDataVo } from '../system/meta-platform/vo/meta-platform-get-realtime-data.vo'
import { MetaPlatformRequestResourceModuleActionVo } from '../system/meta-platform/vo/meta-platform-request-resource-module-action.vo'
import { MetaPlatformApiService } from './meta-platform-api.service'

@Injectable()
export class MetaPlatformApiMockService extends MetaPlatformApiService {
  async requestResourceChart(param: MetaPlatformGetChartDataDto): Promise<MetaPlatformGetChartDataVo> {
    if (param.name === i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-0')) {
      return {
        series: [
          {
            data: [
              { value: 124, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-1') },
              { value: 735, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-2') },
              { value: 580, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-3') },
              { value: 484, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-4') },
              { value: 300, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-5') },
              { value: 300, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-6') },
            ],
          },
        ],
      }
    }

    if (param.name === i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-7')) {
      return {
        series: [
          {
            data: [
              { value: 124, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-8') },
              { value: 735, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-9') },
              { value: 580, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-10') },
            ],
          },
        ],
      }
    }

    if (param.name === i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-11')) {
      return {
        series: [
          {
            data: [
              { value: 124, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-12') },
              { value: 735, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-13') },
              { value: 580, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-14') },
              { value: 580, name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-15') },
            ],
          },
        ],
      }
    }

    if (param.name === i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-16')) {
      return {
        dataHash: '1',
        series: [
          {
            name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-17'),
            data: [320, 332, 301, 334, 390, 330, 320].map((value, index) => ({
              value,
              name: String(index),
            })),
          },
          {
            name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-7'),
            data: [120, 132, 101, 134, 90, 230, 210].map((value, index) => ({
              value,
              name: String(index),
            })),
          },
          {
            name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-18'),
            data: [220, 182, 191, 234, 290, 330, 310].map((value, index) => ({
              value,
              name: String(index),
            })),
          },
          {
            name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-19'),
            data: [150, 232, 201, 154, 190, 330, 410].map((value, index) => ({
              value,
              name: String(index),
            })),
          },
          {
            name: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-20'),
            data: [862, 1018, 964, 1026, 1679, 1600, 1570].map((value, index) => ({
              value,
              name: String(index),
            })),
          },
        ],
      }
    }

    return {
      series: [],
    }
  }

  async requestResourceModuleAction(
    param: MetaPlatformRequestResourceModuleActionDto
  ): Promise<MetaPlatformRequestResourceModuleActionVo> {
    if (param.moduleName === 'notification' && param.actionName === 'dashboard-list') {
      return [
        {
          notificationType: 'danger',
          notificationTypeLabel: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-15'),
          notificationTimestamp: Date.now(),
          notificationMessage: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-21'),
        },
        {
          notificationType: 'warning',
          notificationTypeLabel: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-14'),
          notificationTimestamp: Date.now(),
          notificationMessage: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-21'),
        },
        {
          notificationType: 'info',
          notificationTypeLabel: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-22'),
          notificationTimestamp: Date.now(),
          notificationMessage: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-21'),
        },
        {
          notificationType: 'success',
          notificationTypeLabel: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-23'),
          notificationTimestamp: Date.now(),
          notificationMessage: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-21'),
        },
        {
          notificationType: 'primary',
          notificationTypeLabel: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-24'),
          notificationTimestamp: Date.now(),
          notificationMessage: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-21'),
        },
      ]
    }
    return null
  }

  async requestGetRealtimeData(param: MetaPlatformGetRealtimeDataDto): Promise<MetaPlatformGetRealtimeDataVo> {
    return {
      business: {
        cop_year: [7, Date.now()],
        cop_month: [7.2, Date.now()],
        online_count: [55, Date.now()],
        offline_count: [7, Date.now()],
      },
      device: {
        WCH_1: {
          online: [false, Date.now()],
          speed: ['1', Date.now()],
          temperature: [20, Date.now()],
        },
        WCH_2: {
          online: [true, Date.now()],
          speed: ['2', Date.now()],
          temperature: [30, Date.now()],
        },
        LQT: {
          LQT_1: {
            online: [true, Date.now()],
            water_temperature: [20, Date.now()],
          },
          LQT_2: {
            online: [false, Date.now()],
            water_temperature: [34, Date.now()],
          },
        },
      },
    }
  }

  async requestAuth(param: MetaPlatformAuthDto): Promise<void> {}

  async requestWsAuth(param: MetaPlatformWsAuthDto): Promise<void> {}

  async requestGetBindDataSource(param: MetaPlatformGetBindDataSourceDto): Promise<MetaPlatformGetBindDataSourceVo[]> {
    return [
      {
        name: 'business',
        label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-25'),
        children: [
          {
            name: 'cop_year',
            label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-26'),
          },
          {
            name: 'cop_month',
            label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-27'),
          },
          {
            name: 'online_count',
            label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-28'),
          },
          {
            name: 'offline_count',
            label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-29'),
          },
        ],
      },
      {
        name: 'device',
        label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-30'),
        children: [
          {
            name: 'WCH_1',
            label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-31'),
            children: [
              {
                name: 'online',
                label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-32'),
              },
              {
                name: 'speed',
                label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-33'),
              },
              {
                name: 'temperature',
                label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-34'),
              },
            ],
          },
          {
            name: 'WCH_2',
            label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-35'),
            children: [
              {
                name: 'online',
                label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-32'),
              },
              {
                name: 'speed',
                label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-33'),
              },
              {
                name: 'temperature',
                label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-34'),
              },
            ],
          },
          {
            name: 'LQT',
            label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-36'),
            children: [
              {
                name: 'LQT_1',
                label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-37'),
                children: [
                  {
                    name: 'online',
                    label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-32'),
                  },
                  {
                    name: 'water_temperature',
                    label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-38'),
                  },
                ],
              },
              {
                name: 'LQT_2',
                label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-39'),
                children: [
                  {
                    name: 'online',
                    label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-32'),
                  },
                  {
                    name: 'water_temperature',
                    label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-38'),
                  },
                ],
              },
            ],
          },
        ],
      },
    ]
  }

  async requestGetBindDataSourceType(
    param: MetaPlatformGetBindDataSourceTypeDto
  ): Promise<MetaPlatformGetBindDataSourceTypeVo> {
    const name = String(param.path).split('.').pop()

    switch (param.path) {
      case 'device.WCH_1.online':
      case 'device.WCH_2.online':
      case 'device.LQT.LQT_1.online':
      case 'device.LQT.LQT_2.online':
        return {
          type: DomainModel.MetaResourceModelDataType.Boolean,
          name,
          isWrite: false,
          activeLabel: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-32'),
          inactiveLabel: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-40'),
        }
      case 'device.WCH_1.speed':
      case 'device.WCH_2.speed':
        return {
          type: DomainModel.MetaResourceModelDataType.Enum,
          name,
          isWrite: true,
          mappings: [
            {
              value: '1',
              label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-41'),
            },
            {
              value: '2',
              label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-42'),
            },
            {
              value: '3',
              label: i18n.t('app-meta.meta-platform-api.meta-platform-api.30695111-43'),
            },
          ],
        }
      case 'device.WCH_1.temperature':
      case 'device.WCH_2.temperature':
      case 'device.LQT.LQT_1.water_temperature':
      case 'device.LQT.LQT_2.water_temperature':
        return {
          type: DomainModel.MetaResourceModelDataType.Number,
          name,
          isWrite: true,
          unit: '℃',
          min: 0,
          max: 100,
          step: 0.5,
          precision: 1,
        }
      case 'business.cop_year':
      case 'business.cop_month':
      case 'business.online_count':
      case 'business.offline_count':
        return {
          type: DomainModel.MetaResourceModelDataType.Number,
          name,
          isWrite: false,
        }
    }
  }
}
